package com.shqcjd.sinopecdemomobile.ui.adapter;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shqcjd.sinopecdemomobile.R;
import com.shqcjd.sinopecdemomobile.model.pojo.ExpertReplyDetailBean;
import com.shqcjd.sinopecdemomobile.model.pojo.UploadFileRet;
import com.shqcjd.sinopecdemomobile.ui.activity.preview.PreImageActivity;
import com.shqcjd.sinopecdemomobile.ui.activity.preview.VideosActivity;
import com.shqcjd.sinopecdemomobile.ui.activity.problem.ProblemMoreFileActivity;

import java.io.Serializable;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 解答详情-专家回复列表
 * Created by sy on 2019/5/25.
 */

public class ExpertReplyListAdapter extends BaseQuickAdapter<ExpertReplyDetailBean.ExpertListBean,ExpertReplyListAdapter.ViewHolder> {

    public ExpertReplyListAdapter() {
        super(R.layout.item_expert_reply_details_list);
    }

    @Override
    protected void convert(ExpertReplyListAdapter.ViewHolder helper, ExpertReplyDetailBean.ExpertListBean item) {
        helper.tv_expert_title.setText("专家回复 ("+item.expertUserName+")");
        helper.tv_expert_text.setText(""+item.expertReply);

        ProblemItemImgAdapter expertImgAdapter = new ProblemItemImgAdapter(item.expertReplyAttachments, mContext);
        helper.rv_expert_img_list.setLayoutManager(new GridLayoutManager(mContext, 3));
        helper.rv_expert_img_list.setAdapter(expertImgAdapter);
        expertImgAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                UploadFileRet fileItem = (UploadFileRet) adapter.getItem(position);
                if(adapter.getData().size()>9&&position==8){
                    Intent intent = new Intent(mContext, ProblemMoreFileActivity.class);
                    Bundle bundle=new Bundle();
                    bundle.putSerializable("list",(Serializable)item.expertReplyAttachments);
                    intent.putExtras(bundle);
                    mContext.startActivity(intent);
                }else{
                    if(fileItem.extension.equals(".mp4")){
                        Intent it = new Intent(mContext, VideosActivity.class);
                        it.putExtra("url", fileItem.url);
                        it.putExtra("name", "视频详情");
                        mContext.startActivity(it);
                    }else{
                        Intent it = new Intent(mContext, PreImageActivity.class);
                        it.putExtra("url", fileItem.url);
                        it.putExtra("name", "图片详情");
                        mContext.startActivity(it);
                    }

                }
            }
        });
    }

    class ViewHolder extends BaseViewHolder {
        @BindView(R.id.tv_expert_title)
        TextView tv_expert_title;
        @BindView(R.id.tv_expert_text)
        TextView tv_expert_text;
        @BindView(R.id.rv_expert_img_list)
        RecyclerView rv_expert_img_list;
        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}